package lec;

class MyException extends Exception{
	public MyException( String message){
		super( message );
	}
}
public class Except {
	private static final int MAX_VALUE = 2000;
	private static int compute(int[] y) throws MyException {
		int result = 0;
		for (int x : y)
			result = result + 10000 / (50 - x);
		if ( result > MAX_VALUE )
			throw new MyException("Result is too high!!!!!");
		return result;
	}

	public static void main(String[] args) {
		int[] a = new int[10];

		for (int i = 0; i < a.length; i++)
			a[i] = i;

		for (int i = 0; i < a.length; i++)
			System.out.println("a[" + i + "] is " + a[i]);
		int result=0;
		try {
			result = compute(a);
		} catch (ArithmeticException ae) {
			System.err.println("Caught an error - probably a divide by 0");
		} catch (MyException me){
			me.printStackTrace();
			System.err.println("Caught an exception - exceeded " + MAX_VALUE );
		}
		System.out.println(" The result of the computation is " + result);
	}
}
